<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Title</title>
    <script src="./jessibuca.js"></script>
    <style>
        html, body {
            width: 100%;
            height: 100%;
            overflow: hidden;
        }

        html {
            -ms-text-size-adjust: 100%;
            -webkit-text-size-adjust: 100%;
            -webkit-tap-highlight-color: transparent;
        }

        body {
            line-height: 1.6;
            position: relative;
            font-family: "Microsoft Yahei", tahoma, arial, "Hiragino Sans GB";
        }

        input {
            outline: 0;
        }

        * {
            margin: 0;
            padding: 0;
        }

        * {
            -webkit-tap-highlight-color: transparent
        }

        a img {
            border: 0;
        }

        a {
            text-decoration: none;
        }

        a,
        input,
        button,
        textarea{
        }

        input,
        button,
        textarea {
            color: inherit;
            font: inherit;
        }

        li {
            list-style: none;
        }

        ol,
        ul {
            margin: 0;
            padding: 0;
            list-style: none;
        }



    </style>
    <style>
        html,body{
            width: 100%;
            height: 100%;
            position: relative;
        }

        .root {
            position: relative;
            width: 100%;
            text-align: center;
            /*display: flex;*/
            /*align-items: center;*/
            /*justify-content: center;*/
            /*margin-top: 3rem;*/
        }

        .container-shell {
            backdrop-filter: blur(5px);
            background: hsla(0, 0%, 50%, 0.5);
            padding: 30px 4px 10px 4px;
            /* border: 2px solid black; */
            width: auto;
            position: relative;
            border-radius: 5px;
            box-shadow: 0 10px 20px;
        }

        .container-shell:before {
            content: "jessibuca demo player";
            position: absolute;
            color: darkgray;
            top: 4px;
            left: 10px;
            text-shadow: 1px 1px black;
        }

        #container {
            margin: 0 auto;
            background: rgba(13, 14, 27, 0.7);
            width: 640px;
            height: 398px;
        }

        .input {
            display: flex;
            margin-top: 10px;
            /*color: white;*/
            place-content: stretch;
        }

        .input2 {
            bottom: 0px;
        }

        .input input {
            flex: auto;
        }

        .err {
            position: absolute;
            top: 40px;
            left: 10px;
            color: red;
        }

        .option {
            position: absolute;
            top: 4px;
            right: 10px;
            display: flex;
            place-content: center;
            font-size: 12px;
        }

        .option span {
            color: white;
        }

        .page {
            background: url('./bg.jpg');
            background-repeat: no-repeat;
            background-position: top;
        }

        @media (max-width: 720px) {
            #container {
                width: 90vw;
                height: 52.7vw;
            }
        }
    </style>
</head>
<body class="page">
<div class="root">
    <div class="container-shell">
        <div id="container"></div>
        <div class="input">
            <div>
                <input
                    type="checkbox"
                    id="useWebFullScreen"
                /><span>使用web全屏</span>
            </div>

        </div>
        <div class="input">
            <div>输入URL：</div>
            <input
                autocomplete="on"
                id="playUrl"
                value="https://flvplayer.js.org/assets/video/weathering-with-you.flv"
            />
            <button id="play">播放</button>
            <button id="pause" style="display: none">停止</button>
        </div>
        <div class="input" style="line-height: 30px">
            <button id="fullscreen">全屏</button>

            <button id="destroy">销毁</button>
        </div>
    </div>
</div>

<script>
    var $player = document.getElementById('play');
    var $pause = document.getElementById('pause');
    var $playHref = document.getElementById('playUrl');
    var $container = document.getElementById('container');
    var $destroy = document.getElementById('destroy');
    var $fullscreen = document.getElementById('fullscreen');
    var $useWebFullScreen = document.getElementById('useWebFullScreen');


    var showOperateBtns = true; // 是否显示按钮
    var forceNoOffscreen = true; //
    var jessibuca = null;

    function create() {
        jessibuca = new Jessibuca({
            container: $container,
            videoBuffer: 0.2, // 缓存时长
            isResize: false,
            text: "",
            loadingText: "加载中",
            debug: true,
            showBandwidth: showOperateBtns, // 显示网速
            operateBtns: {
                fullscreen: showOperateBtns,
                screenshot: showOperateBtns,
                play: showOperateBtns,
                audio: showOperateBtns,
            },
            forceNoOffscreen: forceNoOffscreen,
            useWebFullScreen: $useWebFullScreen.checked,
            isNotMute: false,
        },);

        // jessibuca.onLog = msg => console.error(msg);
        // jessibuca.onRecord = (status) => console.log('onRecord', status);
        // jessibuca.onPause = () => console.log('onPause');
        // jessibuca.onPlay = () => console.log('onPlay');
        // jessibuca.onFullscreen = msg => console.log('onFullscreen', msg);
        // jessibuca.onMute = msg => console.log('onMute', msg);
        jessibuca.on('fullscreen',(value)=>{
            console.log('onFullscreen', value);
        })
        $player.style.display = 'inline-block';
        $pause.style.display = 'none';
        $destroy.style.display = 'none';
        $fullscreen.style.display = 'none';
    }


    create();

    function replay() {
        if (jessibuca) {
            jessibuca.destroy().then(()=>{
                create();
                play();
            });
        }
        else {
            create();
            play();
        }

    }

    function play() {
        var href = $playHref.value;
        if (href) {
            jessibuca.play(href);
            $player.style.display = 'none';
            $pause.style.display = 'inline-block';
            $destroy.style.display = 'inline-block';
            $fullscreen.style.display = 'inline-block';

        }
    }

    $player.addEventListener('click', function () {
        play()
    }, false)


    $pause.addEventListener('click', function () {
        $player.style.display = 'inline-block';
        $pause.style.display = 'none';
        jessibuca.pause();
    })

    $destroy.addEventListener('click', function () {
        if (jessibuca) {
            jessibuca.destroy();
        }
        create();
    })

    $fullscreen.addEventListener('click',function () {
        if(jessibuca){
            jessibuca.setFullscreen(true)
        }
    })

    $useWebFullScreen.addEventListener('click', function () {
        replay()
    })

</script>

</body>
</html>
